package action;

import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
import service.OrderService;
import util.OrderPager;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Trialiet on 2016/9/13.
 */
public class TurnoverAction extends ActionSupport {
    private OrderService orderService;
    private String startDate;
    private String endDate;
    private OrderPager orderPager;
//    private JSONArray result;

    public String getDailyTurnover() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        orderPager.setStartDate(sdf.parse(startDate));
        orderPager.setEndDate(sdf.parse(endDate));
        if (orderPager.getMaxPages() == 0){
            orderPager.setMaxPages(orderService.findMaxPages(orderPager));
        }
        List list = orderService.findByPage(orderPager);
        orderPager.setData(list);
//        JsonConfig config = new JsonConfig();
//        config.setExcludes(new String[]{"order"});
//        result = JSONArray.fromObject(orderPager, config);
        return "result";
    }

    public void setOrderService(OrderService orderService) {
        this.orderService = orderService;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

//    public JSONArray getResult() {
//        return result;
//    }
//
//    public void setResult(JSONArray result) {
//        this.result = result;
//    }

    public OrderPager getOrderPager() {
        return orderPager;
    }

    public void setOrderPager(OrderPager orderPager) {
        this.orderPager = orderPager;
    }
}
